const exp = require("express")

const data = require("./data/index")
const app = exp()

app.get("/",(req,res)=>{

    let str = `<ul>`

     data.forEach(item => {
        str+=`<li><a href = "/tatial/${item.id}">${item.newsTitle}</a> </li>`
    });

    str+= `</ul>`
    res.send(str)
    
})

app.get("/tatial/:id",(req,res)=>{
    let {id} = req.params
    let {newsTitle,newsContent}=data.find(item=> item.id === id)
    let str = `
    <h3>${newsTitle}</h3>
    <p>${newsContent}</p>
    `
    res.send(str)
})


app.listen(80,()=>{
    console.log("开启成功");
})